package main

import "fmt"

type Human struct {
	name   string
	age    int
	gender string
}

type Student struct {
	people Human //包含Human类型的变量，此时是类的嵌套
	score  float64
	school string
}

type Teacher struct {
	Human   //直接写Human类型，没有字段名字
	subject string
}

// Eat 在类外绑定方法
// 指针可以修改原有的值
func (this *Human) Eat() {
	fmt.Println("Person is eating")
	//类的方法可以使用自己的成员

}

func main() {
	s1 := Student{
		people: Human{
			name:   "cc",
			age:    18,
			gender: "male",
		},
		school: "caozhuangxiaoxue",
	}

	fmt.Println("s1.name: ", s1.people.name)
	fmt.Println("s1.school: ", s1.school)

	t1 := Teacher{}
	t1.name = "苍老师"
	t1.age = 35
	t1.subject = "艺术"
	fmt.Println("t1: ", t1)
	t1.Eat()

	//继承的时候虽然没有定义字段名称，但是会自动创建一个默认的同名字段
	//这是为了在子类中依然可以操作父类，因为子类父类可能出现同名的字段

	fmt.Println("t1.human.name: ", t1.Human.name)
}
